<?php 

//var_dump($_FILES);

$files = array();

if(!empty($_FILES)) {
	foreach($_FILES as $key => $f) {
		while(file_exists('uploads/' . $f['name'])) {
			$f['name'] = rand(1,9) . $f['name'];
		}
		if(move_uploaded_file($f['tmp_name'], 'uploads/' . $f['name'])) {
			$files[$key] = array('name' => $f['name'], 'path' => 'uploads/' . $f['name']);
		}
	}
}

echo json_encode($files);

?>